#include "widget.h"
#include "ui_widget.h"
#include <QLineEdit>
#include <QVBoxLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    // 创建4个 QLineEdit 对象
    QLineEdit *line1 = new QLineEdit(this);
    QLineEdit *line2 = new QLineEdit(this);
    QLineEdit *line3 = new QLineEdit(this);
    QLineEdit *line4 = new QLineEdit(this);

    // 设置焦点策略,验证FocusPolicy属性
    line1->setFocusPolicy(Qt::StrongFocus);
    line2->setFocusPolicy(Qt::NoFocus);
    line3->setFocusPolicy(Qt::ClickFocus);
    line4->setFocusPolicy(Qt::TabFocus);

    // 创建垂直布局管理器并添加小部件
    QVBoxLayout *formLayout = new QVBoxLayout;
    formLayout->addWidget(line1);
    formLayout->addWidget(line2);
    formLayout->addWidget(line3);
    formLayout->addWidget(line4);
    formLayout->setContentsMargins(50, 50, 50, 50);  // 设置边距

    // 将布局应用到当前 Widget
    this->setLayout(formLayout);
}

Widget::~Widget()
{
    delete ui;
}
